<?php
/**
 * Smart Library - Smart Framework
 * http://smart-framework.highet.eu
 *
 * @category   SmartL
 * @package    SmartL_Profiler
 * @subpackage Custom
 * @copyright  Copyright (c) 2005-2008 Smart Framework team - Stepan Sindelar, Vojtech Vit
 * @license    http://www.opensource.org/licenses/bsd-license.php	New BSD License
 */

/**
 * @see SmartL_Profiler_Custom_Interface
 */
require_once 'SmartL/Profiler/Custom/Interface.php';

/**
 * Abstract class for custom profiler.
 * 
 * Profiler usually output it's data in table. 
 * In this case user should only implement only methods 
 * for retrieve headers of table and iteratorof data to be displyed in table.
 *
 * @package SmartL_Profiler
 * @subpackage Custom
 */
class SmartL_Profiler_Custom_Abstract implements SmartL_Profiler_Custom_Interface {
	/**
	 * Returns name of this custom profiler.
	 *
	 * @return string
	 */
	public function getName() {
		return '';
	}
	/**
	 * Returns headers of output table.
	 *
	 * @return array[numeric]=>string
	 */
	public function getHeaders() {
		return array ();
	}
	/**
	 * Returns iterator of array of values to output in one table row.
	 *
	 * @return Iterator
	 */
	public function getValuesIterator() {
		return new ArrayIterator ( array () );
	}
	
	/**
	 * Generates html table.
	 *
	 * @return string
	 */
	public function getResult() {
		$result = '<table>';
		
		$headers = $this->getHeaders ();
		$result .= "<tr>";
		foreach ( $headers as $header ) {
			$result .= "<th>{$header}</th>";
		}
		$result .= "</tr>";
		
		foreach ( $this->getValuesIterator () as $values ) {
			$result .= "<tr>";
			foreach ( $values as $value ) {
				$result .= "<td>{$value}</td>";
			}
			$result .= "</tr>";
		}
		
		$result .= '</table>';
		
		return $result;
	}
}